import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class RedisTest {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
        try (Jedis jedis = jedisPool.getResource()) {

        }
    }

    //sadd 和 smembers
    public static void testSaddAndSmembers(Jedis jedis) {
        jedis.sadd("set1", "a", "b", "c");
        Set<String> set = jedis.smembers("set1");
        for (String s : set) {
            System.out.println(s);
        }
    }

    //srem 和 sismember
    public static void testSremAndSismember(Jedis jedis) {

        jedis.sadd("set1", "a", "b", "c");

        jedis.srem("set1", "a");
        boolean b = jedis.sismember("set1", "a");
        System.out.println(b);
    }

    //scard
    public static void testScard(Jedis jedis) {

        jedis.sadd("set1", "a", "b", "c");

        long l = jedis.scard("set1");
        System.out.println(l);
    }

    //sinter
    public static void testSinter(Jedis jedis) {
        jedis.sadd("set1", "a", "b", "c");
        jedis.sadd("set2", "a", "b", "d");
        Set<String> set = jedis.sinter("set1", "set2");
        for (String s : set) {
            System.out.println(s);
        }
    }

    //sunion
    public static void testSunion(Jedis jedis) {
        jedis.sadd("set1", "a", "b", "c");
        jedis.sadd("set2", "a", "b", "d");
        Set<String> set = jedis.sunion("set1", "set2");
        for (String s : set) {
            System.out.println(s);
        }
    }

    //sdiff
    public static void testSdiff(Jedis jedis) {
        jedis.sadd("set1", "a", "b", "c");
        jedis.sadd("set2", "a", "b", "d");
        Set<String> set = jedis.sdiff("set1", "set2");
        for (String s : set) {
            System.out.println(s);
        }
    }
}